﻿using System;

namespace YArchitech.Temp
{
	public class HYFlexPipe : HYPipeline
	{
		public double Load { get; set; }

		public int DN { get; set; }

		public double Diameter { get; set; }

		public new double Roughness { get; set; }

		public double KD { get; protected set; }

		public PipeSizeStatus Status { get; set; }

		public new HYPipeSpecification Section
		{
			get
			{
				return this.m_Section as HYPipeSpecification;
			}
			set
			{
				this.m_Section = value;
				this.DN = (this.m_Section as HYPipeSpecification).DN;
				this.Diameter = (this.m_Section as HYPipeSpecification).Diameter;
			}
		}

		public HYFlexPipe()
		{
			this.Status = PipeSizeStatus.Unknown;
			base.Name = "水管";
			this.m_Section = new HYPipeSpecification();
		}

		public override void RebuildIndex(ref int index)
		{
			base.RebuildIndex(ref index);
		}

		public override double CalLambda(HYSystemOption option)
		{
			if (Utility.IsZero(this.Diameter, 1E-05))
			{
				this.m_Rm = 0.0;
				return 0.0;
			}
			double num = this.Diameter / 1000.0;
			base.Re = Hydrokinetics.Re(num, this.m_Velocity, option.Viscosity);
			this.KD = this.Roughness / num;
			this.m_Lambda = Hydrokinetics.Lambda(base.Re, this.KD);
			return this.m_Lambda;
		}

		public override double CalRm(HYSystemOption option)
		{
			if (Utility.IsZero(this.Diameter, 1E-05))
			{
				this.m_Rm = 0.0;
				return 0.0;
			}
			double rs = this.Diameter / 4000.0;
			this.m_Lambda = this.CalLambda(option);
			this.m_Rm = Hydrokinetics.Rm(this.m_Lambda, rs, this.m_Velocity, option.Density);
			return this.m_Rm;
		}

		public override void Cal(HYSystemOption option)
		{
			HYPipeSpecification hypipeSpecification = this.m_Section as HYPipeSpecification;
			base.Cal(option);
			switch ((option as HYPipeSystemOption).Method)
			{
			case HYPipeSystemOption.CalMethod.ByVelocity:
				this.Status = (hypipeSpecification.VelocityRange.Contains(base.Velocity) ? PipeSizeStatus.Suitable : PipeSizeStatus.Unsuitable);
				return;
			case HYPipeSystemOption.CalMethod.ByRm:
				this.Status = (hypipeSpecification.RmRange.Contains(base.Rm) ? PipeSizeStatus.Suitable : PipeSizeStatus.Unsuitable);
				return;
			case HYPipeSystemOption.CalMethod.ByLoad:
				this.Status = (hypipeSpecification.LoadRange.Contains(this.Load) ? PipeSizeStatus.Suitable : PipeSizeStatus.Unsuitable);
				return;
			default:
				return;
			}
		}
	}
}
